<%
  if defined?(shareable_document) && shareable_document
    pdf_url = asset.file.url(disposition: 'attachment', expires_in: Constants::URL_SHORT_EXPIRE_TIME.minutes)
    pdf_size = asset&.blob&.byte_size
  elsif report_document
    pdf_url = rails_blob_path(asset, disposition: 'attachment')
    pdf_size = asset.blob.byte_size
  else
    pdf_url = asset.pdf? ? asset_download_path(asset) : asset_pdf_preview_path(asset)
    pdf_size = !asset.pdf? && asset.pdf_preview_ready? ? asset.file_pdf_preview&.blob&.byte_size : asset.file_size
  end
  blocked = pdf_size > Constants::PDF_PREVIEW_MAX_SIZE_MB.megabyte
%>
<div class="pdf-viewer <%= 'blocked' if blocked %> ">
  <div class="page-container">
    <div class="layers-container">
      <canvas class="pdf-canvas <%= 'ready' unless blocked %>"
        data-pdf-url="<%= pdf_url %>"
        data-pdf-worker-url="<%= asset_path('pdf_js_worker.js') %>"
      ></canvas>
      <div class="textLayer"></div>
    </div>
  </div>
  <div class="pdf-toolbar">
    <button class="btn btn-light icon-btn btn-xs prev-page">
      <i class="sn-icon sn-icon-arrow-left"></i>
    </button>
    <div class="page-counter sci-input-container">
      <input type="text" class="sci-input-field current-page" value=1>
      <%= t('pdf_preview.pages.of') %>
      <span class="total-page">...</span>
    </div>
    <button class="btn btn-light icon-btn btn-xs next-page">
      <i class="sn-icon sn-icon-arrow-right"></i>
    </button>
    <div class="divider"></div>
    <div class="zoom-page">
      <select class="zoom-page-selector">
        <option value="auto"><%= t('pdf_preview.fit_to_screen') %></option>
        <% 12.times.each do |i| %>
          <option value="<%= ((i + 1).to_f * 0.25).to_s.sub(/\.?0+$/, '') %>" <%= 'selected' if (i + 1) * 25 == 100 %>><%= (i + 1) * 25 %>%</option>
        <% end %>
      </select>
    </div>
    <div class="sci-btn-group">
      <button class="btn btn-light icon-btn btn-xs zoom-out">
        <i class="sn-icon sn-icon-minus"></i>
      </button>
      <button class="btn btn-light btn-xs icon-btn zoom-in">
        <i class="sn-icon sn-icon-new-task"></i>
      </button>
    </div>
  </div>
  <div class="blocked-screen">
    <%= image_tag 'pdf_js/blocked.svg', class: 'image' %>
    <p class="title"><%= t('pdf_preview.blocked.title') %></p>
    <p class="description"><%= t('pdf_preview.blocked.description') %></p>
    <button class="btn btn-primary load-blocked-pdf">
      <i class="fas fa-cloud-download-alt"></i>
      <%= t('pdf_preview.blocked.submit_button') %>
    </button>
  </div>
</div>
